home *** CD-ROM | disk | FTP | other *** search
/ APDL Other Worlds / APDL Other Worlds Collection.iso / SF3000 / Extras / CBlibrary / c / NoBudge < prev    next >
Encoding:
Text File  |  2003-10-16  |  2.2 KB  |  78 lines

  1. /*
  2.  * CBLibrary - NoBudge
  3.  * Copyright (C) 2003  Chris Bazley
  4.  *
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU Lesser General Public
  7.  * License as published by the Free Software Foundation; either
  8.  * version 2.1 of the License, or (at your option) any later version.
  9.  *
  10.  * This library is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * Lesser General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU Lesser General Public
  16.  * License along with this library; if not, write to the Free Software
  17.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  */
  19.  
  20. /* Keeps track of multiple operations that require flex budge disabled */
  21.  
  22. /* ANSI library files */
  23. #include <assert.h>
  24. #include <stdlib.h>
  25.  
  26. /* RISC OS library files */
  27. #include "kernel.h"
  28. #include "flex.h"
  29.  
  30. /* My library files */
  31. #include "NoBudge.h"
  32.  
  33. extern _kernel_oserror shared_err_block;
  34. static int default_state, num_no_budge = 0;
  35.  
  36. /* ----------------------------------------------------------------------- */
  37. /*                         Public functions                                */
  38.  
  39. void nobudge_register(size_t heap_ensure)
  40. {
  41.   free(malloc(heap_ensure));
  42.  
  43.   if(num_no_budge == 0) {
  44.     /* We have first client - disable flex budging */
  45. #ifndef NDEBUG
  46.     _kernel_oscli("report NoBudge has first client - disabling flex budging");
  47. #endif
  48.     default_state = flex_set_budge(0);
  49.   }
  50. #ifndef NDEBUG
  51.   _kernel_oscli("report Incrementing NoBudge count");
  52. #endif
  53.   num_no_budge++;
  54. }
  55.  
  56. /* ----------------------------------------------------------------------- */
  57.  
  58. void nobudge_deregister(void)
  59. {
  60.   /* Can't deregister if there are no clients! */
  61.   assert(num_no_budge >= 1);
  62.   if(num_no_budge < 1)
  63.     return; /* bad deregistration */
  64.  
  65.   if(num_no_budge == 1) {
  66.     /* We have run out of clients - enable flex budging */
  67. #ifndef NDEBUG
  68.     _kernel_oscli("report Last NoBudge client has deregistered - restoring flex budge state");
  69. #endif
  70.     flex_set_budge(default_state);
  71.   }
  72.  
  73. #ifndef NDEBUG
  74.   _kernel_oscli("report Decrementing NoBudge count");
  75. #endif
  76.   num_no_budge--;
  77. }
  78.